#pragma once
#include "Shadow.h"
#include "RenderToTexture.h"

namespace mini
{
	class CShadowMap : public CShadow
	{
	public:
		CShadowMap();
		virtual ~CShadowMap();
		virtual int nPassCount()override;
		virtual CShaderUnit* passBegin(DeviceContext* pContext, int nNumber) override;
		virtual void passEnd(DeviceContext* pContext, int nNumber) override;
		virtual void updateMeshMatrix(CShaderUnit* pShaderUnit, CMatrix* pMatrix) override;

	protected:
		virtual void drawDepth(DeviceContext* pContext, CShaderUnit* pShaderUnit);
		virtual void drawScene(DeviceContext* pContext, CShaderUnit* pShaderUnit);
		
	protected:
		CMatrix matrixArray[5];
	};

	//////////////////////////////////////////////////////////////////////////
	class CSoftShadowMap : public CShadowMap
	{
	public:
		CSoftShadowMap();
		virtual ~CSoftShadowMap();
		virtual CShaderUnit* passBegin(DeviceContext* pContext, int nNumber) override;
		virtual void passEnd(DeviceContext* pContext, int nNumber) override;
		bool initShadowTexutre(int nSize);

	private:
		virtual void drawScene(DeviceContext* pContext, CShaderUnit* pShaderUnit) final;
		virtual void drawBlackAndWhite(DeviceContext* pContext, CShaderUnit* pShaderUnit);
		virtual void drawDownSample(DeviceContext* pContext, CShaderUnit* pShaderUnit);

		void _horizontalBlur(DeviceContext* pContext, CShaderUnit* pShaderUnit);
		void _verticalBlur(DeviceContext* pContext, CShaderUnit* pShaderUnit);
		void _drawBlurScreen(DeviceContext* pContext, CShaderUnit* pShaderUnit);

	private:
		CMeshUnit*		  mpMeshUnit = nullptr;
		CRenderToTexture* mpBlackWhiteRenderTexture = nullptr;
		CRenderToTexture* mpDownSampleTexure = nullptr;
		CRenderToTexture* mpHorizontalTexure = nullptr;
		CRenderToTexture* mpVerticalTexure = nullptr;
		CRenderToTexture* mpBlurTexure = nullptr;
	};
}